import { axios } from '@/utils/request'
// 获取审核状态列表
export function approvalStatusListFunc (status) {
  const list = [{ name: 0, value: '待审批', color: '' },
    { name: 2, value: '审批不通过', color: 'red' },
    { name: 1, value: '已完成', color: 'green' },
    { name: 3, value: '申请撤销', color: '' },
    { name: 4, value: '审核中', color: 'blue' }]
  if (status >= 0) {
    let obj = {}
    list.forEach(i => {
      if (status === i.name) {
        obj = i
      }
    })
    return obj
  } else {
    return list
  }
}
export function schoolYearFunc (str) {
  return ['2019-2020', '2020-2021', '2021-2022']
}
export function approvalStatusMapFunc (str) {
  const map = { 待审批: '', 审批不通过: 'red', 已完成: 'green', 申请撤销: '', 审核中: 'blue', 处理中: 'blue' }
  return map[str]
}

// 部门
export function departmentListFunc (params = {}) {
  if (!this) return []
  params = Object.assign({ pageNum: -1, deptPid: 0 }, params)
  return this.$axios.post('api/view/queryDept', params).then(res => {
    const list = this.$get(res, 'data.data.dataList', [])
    // 存储在 vuex 内
    const STORE = this.$store || this.store
    STORE.dispatch('basic/setDeptList', list)
    return list
  }).catch(e => [])
}

// 区域
export function areaListFunc (params = {}) {
  if (!this) return []
  params = Object.assign({ pageNum: -1 }, params)
  return this.$axios.post('api/view/queryArea', params).then(res => {
    const list = this.$get(res, 'data.data.dataList', [])
    const STORE = this.$store || this.store
    STORE.dispatch('basic/setAreaList', list)
    return list
  }).catch(e => [])
}

// 年级
export function gradeListFunc (params = {}) {
  if (!this) return []
  params = Object.assign({ groupName: '年级', pageNum: -1 }, params)
  return this.$axios.post('api/view/queryDept', params).then(res => {
    const list = this.$get(res, 'data.data.dataList', [])
    return list
  }).catch(e => [])
}

// 班级
export function classListFunc (params = {}) {
  if (!this) return []
  params = Object.assign({ groupName: '班级', pageNum: -1 }, params)
  return this.$axios.post('api/view/queryDept', params).then(res => {
    const list = this.$get(res, 'data.data.dataList', [])
    // 存储在 vuex 内
    return list
  }).catch(e => [])
}

/**
 * 员工列表查询
 * @param {Object} params { pageNum, pageSize, deptId: {number} 部门 id }
 */
export function teacherListFunc (params) {
  if (!this) return []
  params = Object.assign({ pageNum: -1, pageSize: -1 }, params)
  return this.$axios.post('api/admin/staff/page', params).then(res => {
    const list = this.$get(res, 'data.data.records', [])
    const STORE = this.$store || this.store
    STORE.dispatch('basic/setTeacherList', list)
    return list
  }).catch(e => [])
}

export function getStaff (data) {
  return axios({
    url: '/admin/staff/page',
    method: 'post',
    data
  })
}
